package com.ice_hufs.medical_in_myhand;

import java.text.DateFormat;
import java.util.Calendar;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.TimePicker;

public class reservation_date extends Activity {
            // 년월일, 시분 저장소
    Calendar calendar = Calendar.getInstance();
    TextView txtLabel;

    DatePickerDialog.OnDateSetListener dateSetListener =
    new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            calendar.set(year, monthOfYear, dayOfMonth);
            setLabel();
        }
    };

    TimePickerDialog.OnTimeSetListener timeSetListenr =
    new TimePickerDialog.OnTimeSetListener() {
        @Override
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
            calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
            calendar.set(Calendar.MINUTE, minute);
            setLabel();
        }
    };

            /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_reservation);

        Button btnDate = (Button)findViewById(R.id.btnSetDate);

        btnDate.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View v) {
                new DatePickerDialog(reservation_date.this,
                        dateSetListener,
                        calendar.get(Calendar.YEAR),
                        calendar.get(Calendar.MONTH),
                        calendar.get(Calendar.DAY_OF_MONTH)).show();
            }
        });

        Button btnTime = (Button)findViewById(R.id.btnSetTime);

        btnTime.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View v) {
                new TimePickerDialog(reservation_date.this,
                        timeSetListenr,
                        calendar.get(Calendar.HOUR_OF_DAY),
                        calendar.get(Calendar.MINUTE),true).show();
            }
        });

        txtLabel = (TextView)findViewById(R.id.txtTime);
        setLabel();
    }

    private void setLabel() {
        txtLabel.setText(DateFormat.getDateTimeInstance().format(calendar.getTime()));
    }
}
